﻿<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=mTePrDFVkrXBzMWmNCdemNTp"></script>
@model SalesOrder
@section ToolBar{}
<div class="l-m-form">
    <form mark="LedinghuoForm" action="@Url.Action("Edit")" method="POST">
        @Html.LEditorFor(m => m.SalesOrderNo, Html.TextBoxFor, new { @disabled = "disabled" }, false)
        @Html.HiddenFor(m => m.SalesOrderNo)
        <div class="form-item inline-block">
            <div class="label c5">业务员</div>
            <div class="req">*</div>
            <div class="content">
                @Html.LTextEdit("OrderEmployeeBox", (Model.OrderEmployee != null) ? Model.OrderEmployee.EmployeeName : "", "OrderEmployeeId", "text", new { data = Model.OrderEmployeeId, @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6 commonbox", fa = "fa-angle-down" }, new { req = new { message = "业务员不允许空" } }, null)
            </div>
        </div>

        <div class="form-item">
            <div class="label c5">客户</div>
            <div class="req">*</div>
            <div class="content">
                @Html.LTextEdit("CustomerBox", (Model.Customer != null) ? Model.Customer.CustomerName : "", "CustomerId", "text", new { data = Model.CustomerId, @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6 commonbox", fa = "fa-angle-down" }, new { req = new { message = "客户不允许空" } }, null)
            </div>
        </div>
        <div class="form-item">
            <div class="label c5">仓库</div>
            <div class="req">*</div>
            <div class="content">
                @Html.LTextEdit("StoreBox", (Model.Store != null) ? Model.Store.StoreName : "", "StoreId", "text", new { data = Model.StoreId, @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6 commonbox", fa = "fa-angle-down" }, new { req = new { message = "仓库不允许空" } }, null)
            </div>
        </div>

        <div class="form-item">
            <div class="label c5">交货类型</div>
            <div class="content">
                @if (Model.DeliveryTypeId == DeliveryType.Delivery)
                {
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 1, new { id = "Distribution", @checked = "checked" })<label for="Distribution" class="radio-for">配送</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 2, new { id = "PickUp" })<label for="PickUp" class="radio-for">客户自提</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 3, new { id = "Delivery" })<label for="Delivery" class="radio-for">当场交货</label>
                }
                @if (Model.DeliveryTypeId == DeliveryType.RealTimeDelivery)
                {
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 1, new { id = "Distribution" })<label for="Distribution" class="radio-for">配送</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 2, new { id = "PickUp" })<label for="PickUp" class="radio-for">客户自提</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 3, new { id = "Delivery", @checked = "checked" })<label for="Delivery" class="radio-for">当场交货</label>
                }
                @if (Model.DeliveryTypeId == DeliveryType.PickUp)
                {
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 1, new { id = "Distribution" })<label for="Distribution" class="radio-for">配送</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 2, new { id = "PickUp", @checked = "checked" })<label for="PickUp" class="radio-for">客户自提</label>
                    @Html.RadioButtonFor(m => m.DeliveryTypeId, 3, new { id = "Delivery" })<label for="Delivery" class="radio-for">当场交货</label>
                }
            </div>
        </div>
        <div class="form-item" id="DistributionInfo">
            <input type="hidden" name="X" id="X" value="@Model.X" />
            <input type="hidden" name="Y" id="Y" value="@Model.Y" />
            @Html.Hidden("IsMapped", Model.IsMapped)
            @if (Model.DeliveryTypeId == DeliveryType.Delivery)
            {
                <div class="relative inline-block">
                    <div class="label c5">收货地址</div>
                    <div class="req">*</div>
                    <div class="content">
                        @Html.LEditor(m => m.Address, Html.TextBoxFor, new { @class = "mapaddress" }, new { req = new { message = "收货地址不允许空" } }, null)
                    </div>
                </div>
                <div class="relative inline-block">
                    <div class="label c5">联系人</div>
                    <div class="req">*</div>
                    <div class="content">@Html.LEditor(m => m.ContactName, Html.TextBoxFor, new { @class = "inp-lg4" }, new { req = new { message = "联系人不允许空" } }, null)</div>
                </div>
                <div class="relative inline-block">
                    <div class="label c5">联系电话</div>
                    <div class="req">*</div>
                    <div class="content">@Html.LEditor(m => m.Phone, Html.TextBoxFor, new { @class = "inp-lg4" }, new { req = new { message = "联系电话不允许空" } }, null)</div>
                </div>
            }
            else
            {
                <div class="relative inline-block">
                    <div class="label c5">收货地址</div>
                    <div class="req">*</div>
                    <div class="content">
                        @Html.LEditor(m => m.Address, Html.TextBoxFor, new { @class = "mapaddress",disabled= "disabled" }, new { req = new { message = "收货地址不允许空" } }, null)
                    </div>
                </div>
                <div class="relative inline-block">
                    <div class="label c5">联系人</div>
                    <div class="req">*</div>
                    <div class="content">@Html.LEditor(m => m.ContactName, Html.TextBoxFor, new { @class = "inp-lg4",disabled = "disabled" }, new { req = new { message = "联系人不允许空" } }, null)</div>
                </div>
                <div class="relative inline-block">
                    <div class="label c5">联系电话</div>
                    <div class="req">*</div>
                    <div class="content">@Html.LEditor(m => m.Phone, Html.TextBoxFor, new { @class = "inp-lg4" , disabled = "disabled" }, new { req = new { message = "联系电话不允许空" } }, null)</div>
                </div>

            }
        </div>
        @*<div class="form-item" id="allmap" style="height:300px;display:none"></div>*@
        @Html.LTextEditFor("PlanDeliveryTime", "配送时间", Model.PlanDeliveryTime.TimeFormat("yyyy-MM-dd"), new { @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6" }, new { req = new { message = "配送时间不允许空" } }, null)

        @{Html.RenderPartial("SalesOrderLine", Model.SalesOrderLines);}

        @*<div class="form-item">
                    <div class="label c5">优惠前金额</div>
                    <div class="content"><em id="Amount">@Model.Amount.MoneyFormat()</em></div>
                </div>
                <div class="form-item">
                    <div class="label c5">优惠后金额</div>
                    <div class="content">
                        <em id="FavourableAmount">@Model.FavourableAmount.MoneyFormat()</em>
                    </div>
            </div>*@

        @Html.LEditorFor(m => m.ActualAmount, Html.TextBoxFor)
        <input type="hidden" name="Amount" value="@Model.Amount" />
        <input type="hidden" name="FavourableAmount" value="@Model.FavourableAmount" />
        <input type="hidden" id="SalesOrderCapitalAmount" name="SalesOrderCapitalAmount" value="0" />
        <input type="hidden" id="PaymentTypeId" name="PaymentTypeId" value="1" />
        @*@if (Model.SalesOrderId <= 0)
            {
                <div class="form-item inline-block">
                    <div class="label c5">现场收款金额</div>
                    <div class="req">*</div>
                    <div class="content">@Html.LTextEdit("SalesOrderCapitalAmount", new { @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6" }, new { req = new { message = "现场收款金额不允许空" } }, null)</div>
                </div>
                <div class="form-item inline-block">
                    <div class="label c5">支付方式</div>
                    <div class="req">*</div>
                    <div class="content">
                        @Html.LTextEdit("PaymentTypeBox", "", "PaymentTypeId", "text", new { data = 1, @class = "inp-text bc1 bgc0 inp-lg7 inp-hg6 commonbox", fa = "fa-angle-down" }, new { req = new { message = "支付方式不允许空" } }, null)
                    </div>
                </div>
            }*@
        @Html.LEditorFor(m => m.Remark, Html.TextAreaFor)
        @Html.LEditorFor(m => m.DeliveryRemark, Html.TextAreaFor)
        @Html.LButton("保存")
    </form>
    @Html.LPageError()
</div>
<script type="text/javascript">
    $(function () {
        $("#OrderEmployeeBox").employee(function ($this) {
            $("#OrderEmployeeId").val($this.attr("data"));
        });
        $("#CustomerBox").customer(function ($this) {
            $("#CustomerId").val($this.attr("data"));
        });
        $("#StoreBox").store(function ($this) {
            $("#StoreId").val($this.attr("data"));
        });
        //$("#PaymentTypeBox").paymentType(function ($this) {
        //    $("#PaymentTypeId").val($this.attr("data"));
        //});


        //配送、当场交货切换
        $("input:radio[name=DeliveryTypeId]").bind("change", function () {
            var $this = $(this);
            var v = $this.val();

            var $DistributionInfo = $("#DistributionInfo");
            var $text=$DistributionInfo.find("input:text");
            if (v == 1) {//配送
                $text.removeAttr("disabled");
                $("a[mark=MapAddree]").removeClass("disable");
                $DistributionInfo.children().each(function(index,ret) {
                    var $ret = $(ret);
                    var $content=$ret.find(".content");
                    $content.before("<div class='req'>*</div>");
                    $content.find("acronym").prepend("<req message='"+$ret.find(".label").text()+"不允许空'></req>");
                });
            } else {
                $text.attr("disabled", "disabled");
                $("a[mark=MapAddree]").addClass("disable");
                var $content = $DistributionInfo.find(".content");
                $DistributionInfo.find(".req").remove();
                $DistributionInfo.find(".error").attr("class", "nomal");
                $content.find("acronym").find("req[message]").remove();
            }
        });
        
        $(document).on("click", "a[mark=MapAddree]:not(.disable)", function () {
            $.LWindow({
                title: "地图",
                id: "Window-Map",
                width: 1024,
                height: 500,
                url: "/Customer/MapAddress",
                callback: function () {

                }
            });
        });
    });
</script>